﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IService.Model;
using IService.Business;
using IService.DataDLL.Utility;

namespace IService.User_center
{
    public partial class ViewMySupplyPurchase : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            SupplyPurchase info = DTVBusiness.SupplyPurchaseManager.GetSupplyPurchaseById(Convert.ToInt32(SupplyPurchaseId));
            Dictionary<string, string> resultVideo = new Dictionary<string, string>();
            resultVideo.Add("Video1", "");
            resultVideo.Add("Video2", "");
            resultVideo.Add("Video3", "");
            VideoList = resultVideo;

            //显示TAB(采购/供应)
            if (info.Type == 1)
            {
                //供应
                //隐藏采购
                this.tab2.Style.Add("display", "none");
                //邦定下拉框
                string[] chkSelect = info.ProductType.Split(',');
                foreach (string select in chkSelect)
                {
                    for (int i = 0; i < this.cblSupplyProductType.Items.Count; i++)
                    {
                        if (string.Compare(this.cblSupplyProductType.Items[i].Value, select, true) == 0)
                        {
                            this.cblSupplyProductType.Items[i].Selected = true;
                        }
                    }
                }
                this.txtSupplyProductName.Text = info.ProductName;
                this.txtSupplyInfoTitle.Text = info.InfoTitle;
                ProductDetail = info.ProductDetail;
                //this.txtareaSupplyProductDetailt.Value = info.ProductDetail;
            }
            else
            {
                //采购
                //隐藏供应
                this.tab1.Style.Add("display", "none");

                //邦定下拉框
                string[] chkSelect = info.ProductType.Split(',');
                foreach (string select in chkSelect)
                {
                    for (int i = 0; i < this.cblPurchaseProductType.Items.Count; i++)
                    {
                        if (string.Compare(this.cblPurchaseProductType.Items[i].Value, select, true) == 0)
                        {
                            this.cblPurchaseProductType.Items[i].Selected = true;
                        }
                    }
                }
                this.txtPurchaseProductName.Text = info.ProductName;
                this.txtPurchaseInfoTitle.Text = info.InfoTitle;
                ProductDetail = info.ProductDetail;
                //this.txtareaPurchaseProductDetail.Value = info.ProductDetail;

                //采购产品图片
                string[] imgs = info.ProductPicture.Split('&');
                if (imgs.Length > 0)
                {
                    for (int i = 0; i < imgs.Length; i++)
                    {
                        if (i == 0)
                        {
                            imgProduct1.ImageUrl = imgs[i];
                        }
                        else if (i == 1)
                        {
                            imgProduct2.ImageUrl = imgs[i];
                        }
                        else
                        {
                            imgProduct3.ImageUrl = imgs[i];
                        }
                    }
                }

                //采购产品视频
                string[] videos = info.ProductVideo.Split('&');
                if (videos.Length > 0)
                {
                    if (videos.Length >= 1 && !string.IsNullOrEmpty(videos[0]))
                    {
                        resultVideo["Video1"] = videos[0];
                        imgProduct4.ImageUrl = "../images/video_view.jpg";
                    }

                    if (videos.Length >= 2 && !string.IsNullOrEmpty(videos[1]))
                    {
                        resultVideo["Video2"] = videos[1];
                        imgProduct5.ImageUrl = "../images/video_view.jpg";
                    }

                    if (videos.Length >= 3 && !string.IsNullOrEmpty(videos[2]))
                    {
                        resultVideo["Video3"] = videos[2];
                        imgProduct6.ImageUrl = "../images/video_view.jpg";
                    }
                    VideoList = resultVideo;
                    //for (int i = 0; i < videos.Length; i++)
                    //{
                    //    if (i == 0)
                    //    {

                    //        imgProduct4.ImageUrl = imgs[i];
                    //    }
                    //    else if (i == 1)
                    //    {
                    //        imgProduct5.ImageUrl = imgs[i];
                    //    }
                    //    else
                    //    {
                    //        imgProduct6.ImageUrl = imgs[i];
                    //    }
                    //}
                }

            }

            this.RequestType = info.RequestType;
            this.CreateDate = info.CreateDate;
            this.lblSupplyPurchaseType.Text = GetSupplyPurchaseType(info.RequestType, info.Type);
            this.Label1.Text = GetSupplyPurchaseType(info.RequestType, info.Type);
            //txtareaSupplyProductDetailt.Disabled = true;
            //txtareaSupplyProductDetailt.Disabled = true;
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSupply_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(GetType(), "SUBMITTED", "window.returnValue=true;window.close();", true);
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPurchase_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(GetType(), "SUBMITTED", "window.returnValue=true;window.close();", true);
        }

        protected int RequestType
        {
            get
            {
                try
                {
                    return Convert.ToInt32(this.ViewState["RequestType"]);
                }
                catch
                {
                    return 1;
                }
            }
            set
            {
                this.ViewState["RequestType"] = value;
            }
        }

        protected DateTime CreateDate
        {
            get
            {
                try
                {
                    return Convert.ToDateTime(this.ViewState["CreateDate"]);
                }
                catch
                {
                    return DateTime.Now;
                }
            }
            set
            {
                this.ViewState["CreateDate"] = value;
            }
        }

        protected string SupplyPurchaseId
        {
            get
            {
                return base.Request["SupplyPurchaseId"];
            }
        }

        //获取需求分类
        public string GetSupplyPurchaseType(int requestType, int type)
        {
            string result = "";

            switch (requestType)
            {
                case 1:
                    if (type == 1)
                        result = "产品采购";
                    else
                        result = "产品供应";
                    break;
                case 2:
                    if (type == 1)
                        result = "技术求购";
                    else
                        result = "技术供应";
                    break;
                case 3:
                    if (type == 1)
                        result = "股权投资";
                    else
                        result = "股权转让";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }

        protected Dictionary<string, string> VideoList
        {
            get
            {
                return (this.ViewState["VideoList"] as Dictionary<string, string>);
            }
            set
            {
                this.ViewState["VideoList"] = value;
            }
        }

        protected string ProductDetail
        {
            get
            {
                return Server.HtmlDecode(this.ViewState["ProductDetail"].ToString());
            }
            set
            {
                this.ViewState["ProductDetail"] = value;
            }
        }
    }
}